<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.Calendar,com.mongodb.client.MongoCursor,org.bson.Document" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>当前学年学期设置</title>
</head>
<body>
	<%
		Document result = (Document)request.getAttribute("result");
		Calendar now = Calendar.getInstance();  
    	int year = now.get(Calendar.YEAR);  // 获取当前年份
    	String[] yearList = new String[5];
    	int flag = -3;
    	for(int i=0; i<5; i++) {
    		int year1 = year + flag;
    		int year2 = year + flag + 1;
    		yearList[i] = year1  + " - " + year2;
    		flag += 1;
    	}
    	String[] semesterList = {"1", "2"};
    %>
    <jsp:include page="../navbar.html" />
    <%if(result == null) { %>
	<div class="row mt30">
		<div class="col-md-6 col-md-offset-3">
			<div class="panel">
             	<div class="panel-body">
               		<h4 class="page-header mt0">设置学年学期</h4>
             		<form name="yearform" role="form" action="schoolYearSemester" method="post" class="form-horizontal mt20">
            			<fieldset>
            			 	<div class="form-group mt15">	
            			 		<label class="col-md-2 control-label">学年</label>				  
               					<div class="col-sm-3">
                  					<select class="form-control" name="year">
                  						<%for(int i=0; i<yearList.length; i++) { %>
	              							<option value="<%=yearList[i] %>"><%=yearList[i] %></option>
	              						<%} %>
                 					 </select>
              					</div>
              					<label class="col-md-1 control-label">学期</label>				  
               					<div class="col-sm-3">
                  					<select class="form-control" name="semester">
                  						<%for(int i=0; i<semesterList.length; i++) { %>
	              							<option value="<%=semesterList[i] %>"><%=semesterList[i] %></option>
	              						<%} %>
                 					 </select>
              					</div>
              					<div class="col-sm-2">
              						<button type="submit" class="btn btn-primary btn-block" name="method" value="add">添加</button>
              					</div>
              				</div>
            			</fieldset> 
            		</form>
            	</div>
         	</div>
      	</div>
	</div>
	<%} else { %>
	<div class="row mt20">
		<div class="col-md-6 col-md-offset-3">
			<div class="panel">
             	<div class="panel-body">
               		<h4 class="page-header mt0">当前学年学期</h4>
             		<span class="text-primary"><%=result.getString("year") %></span> 学年第 <span class="text-primary"><%=result.getString("semester") %></span> 学期
             		<button type="button" class="btn btn-success pull-right" id="updateBtn">修改</button>
            	</div>
         	</div>
      	</div>
	</div>
	<div class="row mt20" style="display:none;" id="updateForm">
		<div class="col-md-6 col-md-offset-3">
			<div class="panel">
             	<div class="panel-body">
               		<h4 class="page-header mt0">修改学年学期</h4>
             		<form name="yearform2" role="form" action="schoolYearSemester" method="post" class="form-horizontal mt20">
            			<fieldset>
            			 	<div class="form-group mt15">	
            			 		<label class="col-md-2 control-label">学年</label>				  
               					<div class="col-sm-3">
                  					<select class="form-control" name="year">
                  						<%for(int i=0; i<yearList.length; i++) { %>
	              							<option value="<%=yearList[i] %>" <%=yearList[i].equals(result.getString("year")) ? "selected" : ""%>><%=yearList[i] %></option>
	              						<%} %>
                 					 </select>
              					</div>
              					<label class="col-md-1 control-label">学期</label>				  
               					<div class="col-sm-3">
                  					<select class="form-control" name="semester">
                  						<%for(int i=0; i<semesterList.length; i++) { %>
	              							<option value="<%=semesterList[i] %>" <%=semesterList[i].equals(result.getString("semester")) ? "selected" : ""%>><%=semesterList[i] %></option>
	              						<%} %>
                 					 </select>
              					</div>
              					<input type="hidden" name="_id" value="<%=result.getObjectId("_id") %>">
              					<div class="col-sm-2">
              						<button type="submit" class="btn btn-primary btn-block" name="method" value="update">确定</button>
              					</div>
              				</div>
            			</fieldset> 
            		</form>
            	</div>
         	</div>
      	</div>
	</div>
	<%} %>
	<script>
	$(document).ready(function(){
	  $("#updateBtn").click(function(){
	    $("#updateForm").fadeIn();
	  });
	});
</script>
</body>
</html>